package com.whfc.ms.api.fenceEdge;

import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.env.entity.FenceEdgeDevice;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fim.service.MsFenceEdgeDeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/ms/api/fenceEdgeDevice")
public class MsFenceEdgeDeviceController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsFenceEdgeDeviceService msFenceEdgeDeviceService;

    @GetMapping("/listPage")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam(value = "name", required = false) String name) {
        logger.info("临边防护列表，loginer:{},pageNum:{},pageSize:{},deptId:{},name:{}",
                user.getUsername(), pageNum, pageSize, deptId, name);
        PageData<FenceEdgeDevice> pageData = msFenceEdgeDeviceService.listPage(pageNum, pageSize, deptId, name);
        return ResultUtil.success(pageData);
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody FenceEdgeDevice request) {
        logger.info("临边防护-添加设备，loginer:{},request:{}", user.getUsername(), request.toString());
        msFenceEdgeDeviceService.add(request);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody FenceEdgeDevice request) {
        logger.info("临边防护-编辑设备，loginer:{},request:{}", user.getUsername(), request.toString());
        msFenceEdgeDeviceService.edit(request);
        return ResultUtil.success();
    }

    @PostMapping("/del")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody FenceEdgeDevice request) {
        logger.info("临边防护-删除设备，loginer:{},request:{}", user.getUsername(), request.toString());
        msFenceEdgeDeviceService.del(request);
        return ResultUtil.success();
    }

}
